package com.abc.webfirst;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.*;

import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=UTF-8");

        //1.获取客户的请求
        String username = request.getParameter("username");
        String pwd = request.getParameter("pwd");
        //2.处理请求，完成业务逻辑(调用相应方法）
        //链接数据库处理……
        if(1+1 == 2){
            response.sendRedirect("center.jsp");
        }else{
            request.setAttribute("loginError","账号密码错误，请重试！");
            request.getRequestDispatcher("login.jsp").forward(request, response);
        }
        //3.做出响应
        response.setContentType("text/html;charset=UTF-8");

    }
}
